@api.route('/list-files')
def list_files():
    # # 确定项目的根目录
    # project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
    #
    # # 初始化结果
    # result = {"root": project_root, "dirs": []}
    #
    # # 遍历目录内容
    # def walk_directory(root):
    #     dir_info = {"dir": os.path.basename(root), "path": root, "items": []}
    #
    #     for child in os.listdir(root):
    #         child_path = os.path.join(root, child)
    #
    #         if os.path.isdir(child_path):
    #             dir_info["items"].append(walk_directory(child_path))
    #         else:
    #             dir_info["items"].append({"file": child, "path": child_path})
    #
    #     return dir_info
    #
    # # 从项目的根目录开始遍历
    # result["dirs"] = [walk_directory(project_root)]
    #
    # # 返回结果
    # return jsonify(result)


    project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

    # 初始化结果
    result = {"root": project_root, "directories": [], "files": []}

    # 遍历目录内容
    for root, dirs, files in os.walk(project_root):
        # 添加当前目录
        result["directories"].append(root)

        # 添加当前目录下的文件
        for file in files:
            result["files"].append(os.path.join(root, file))

    # 返回结果
    return jsonify(result)
